import FileMenu from './childmenu/filemenu.js'
import EditMenu from './childmenu/editmenu.js'
import ViewMenu from './childmenu/viewmenu.js'
import AlignMenu from './childmenu/alignmenu.js'
import LayMenu from './childmenu/laymenu.js'
import fontmenu from './childmenu/fontmenu.js'
import drawmenu from './childmenu/drawmenu.js'
import sysmenu from './childmenu/sysmenu.js'
import animatemenu from './childmenu/animatemenu.js'
import systoolmenu from './childmenu/systoolmenu.js'
import runningmodemenu from './childmenu/runningmodemenu.js'
import editmodemenu from './childmenu/editmodemenu.js'
import exportmenu from './childmenu/exportmenu.js'
import usermenu from './childmenu/usermenu.js'

class MenuActionFactory {
    constructor() {
        this.menuList = [];
    }

    createAction(map, menuItem) {
        var menu_prefixPos = menuItem.indexOf("_");
        var menu_prefix = menuItem.substr(0, menu_prefixPos);
        var subStrLen = menuItem.length - menu_prefixPos - 1;
        var menuSubItem = menuItem.substr(menu_prefixPos + 1, subStrLen);
        var curentMenu = this.findPreMenu(menu_prefix);
        if (!curentMenu) {
            switch (menu_prefix) {
                case 'file':
                    curentMenu = new FileMenu.FileMenu(map, menuSubItem);
                    break;
                case 'edit':
                    curentMenu = new EditMenu.EditMenu(map, menuSubItem);
                    break;
                case 'view':
                    curentMenu = new ViewMenu.ViewMenu(map, menuSubItem);
                    break;
                case 'align':
                    curentMenu = new AlignMenu.AlignMenu(map, menuSubItem);
                    break;
                case 'lay':
                    curentMenu = new LayMenu.LayMenu(map, menuSubItem);
                    break;
                case 'font':
                    curentMenu = new fontmenu.FontMenu(map, menuSubItem);
                    break;
                case 'draw':
                    curentMenu = new drawmenu.DrawMenu(map, menuSubItem);
                    break;
                case 'sys':
                    curentMenu = new sysmenu.SysMenu(map, menuSubItem);
                    break;
                case 'animate':
                    curentMenu = new animatemenu.AnimateMenu(map, menuSubItem);
                    break;

                case 'sysTool':
                    curentMenu = new systoolmenu.SysToolMenu(map, menuSubItem);
                    break;

                case 'runningMode':
                    curentMenu = new runningmodemenu.RunningModeMenu(map, menuSubItem);
                    break;

                case 'editMode':
                    curentMenu = new editmodemenu.EditModeMenu(map, menuSubItem);
                    break;

                case 'export':
                    curentMenu = new exportmenu.ExportMenu(map, menuSubItem);
                    break;

                case 'user':
                    curentMenu = new usermenu.UserMenu(map, menuSubItem);
                    break;
                case 'sysmain':
                    curentMenu = new usermenu.UserMenu(map, menuSubItem);
                    break;

                default:
                    break;
            }
            if (curentMenu) {
                let t = { menu: curentMenu, title: menu_prefix };
                this.menuList.push(t);
            }
        }
        if (curentMenu){
            curentMenu.menuSubItem = menuSubItem;
            curentMenu.map = map;
        }
        return curentMenu;
    }

    findPreMenu(menu_prefix) {
        let dstMenu = null;
        for (let i = 0; i < this.menuList.length; i++) {
            let t = this.menuList[i];
            if (t.title == menu_prefix) {
                dstMenu = t.menu;
                break;
            }
        }
        return dstMenu;
    }

}

export default { MenuActionFactory }

